package cn.itcast.usermanage.controller;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

import cn.itcast.usermanage.pojo.Search;
import cn.itcast.usermanage.pojo.Videl;
import cn.itcast.usermanage.service.SearchService;
import cn.itcast.usermanage.service.VidelService;

@RequestMapping("/videl")
@Controller
public class VidelController {

    @Autowired
    private VidelService videlService;
    
    @Autowired
    private SearchService searchService;
    
    @RequestMapping(value ="/search" ,method=RequestMethod.GET,produces="application/json;charset=UTF-8")
    @ResponseBody
    public String queryVidel(int id ) throws JsonProcessingException{       
        Search record = new Search();
        record.setId(id);
        Search search = this.searchService.queryone(record);
        Map<String , Object> map = new LinkedHashMap<String , Object>();
        map.put("courseId", search.getId());
        
        map.put("courseName", search.getTitle());
        
        Videl videl = new Videl();
        videl.setSid(id);
        List<Videl> list = this.videlService.queryBySid(videl);
        map.put("videl",list);
        ObjectMapper mapper = new ObjectMapper();
        String data = mapper.writeValueAsString(map);
        return data;
    }
}
